package org.shj.jvm.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * 内存占位符对象，一个OOMObject大约占64K
 * 
 * 此例演示用jConsole观察内存使用情况
 * 
 * @author huangjian
 *
 */
public class OOMObject {
	
	public byte[] placeholder = new byte[64*1024];

	public static void fillHeap(int num) throws InterruptedException{
		List<OOMObject> list = new ArrayList<>();
		for(int i = 0 ; i < num ; i++){
			Thread.sleep(50);
			list.add(new OOMObject());
		}
		System.gc();
	}
	
	public static void main(String[] args) throws Exception{
		fillHeap(1000);
	}
}
